package com.common.validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 大忽悠
 * @create 2022/8/24 15:04
 */
public class CustomContainsConstraintValidator implements ConstraintValidator<CustomContains, Integer> {
    private int[] legalValues;

    @Override
    public void initialize(CustomContains constraintAnnotation) {
        legalValues=constraintAnnotation.value();
    }


    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if(value==null){
            return true;
        }
        for (Integer legalValue : legalValues) {
             if(legalValue.equals(value)){
                 return true;
             }
        }
        return false;
    }
}
